<?php
/**
 * Created by PhpStorm.
 * User: yellow
 * Date: 2019/7/15
 * Time: 18:02
 */

namespace app\admin\logic;
use app\admin\logic\code\ErrorCode;
use app\common\model\Bus;
use app\common\model\BusDriver;
use app\common\model\BusBusiness;
use app\common\model\UserInfo;
use app\common\model\Order;
class IndexLogic extends BaseLogic
{
    public function getAudit(){
        $audit[] = BusBusiness::where('status','eq',3)->count();
        $audit[] = Bus::where('state','eq',1)->count();
        $audit[] = BusDriver::where('is_state','eq',0)->count();
        $audit[] = UserInfo::where('status','eq',1)->count();
        return $audit;
    }

    public function getCount(){
        $count[] = Order::alias('as o')
            ->join(config('database.prefix').'order_price op','op.order_id=o.id')
            ->where('o.status','in','3,7,8')->sum('pay_price');
        $count[] = Order::where('status','in','3,7,8')->count();
        $count[] = UserInfo::count();
        $count[] = BusBusiness::count();
        $count[] = Bus::count();
        $count[] = BusDriver::count();
        return $count;
    }

    public function getOrder(){
        $order = Order::with(['beginCity','endCity','price'])->where('status','in','3,7,8')->limit(3)->order('pay_time desc')->select();
        return $order;
    }
}